
import {apiHost,remoteHost} from '../config'
let _stream = null;
export default {
    methods: {
        jump(to) {
            if (this.$router) {
                this.$router.push(to)
            }
        },
        absUrl(url) {
            if (!url) {
                return url;
            }
            if (typeof url == 'string') {
                if (url.indexOf('://') == -1) {
                    return remoteHost + url
                }
            }
            return url
        },
        apiUrl(url){
            if(!url){
                return url;
            }
            if(typeof url == 'string'){
                if(url.indexOf('://') == -1){
                    return apiHost + url
                }
            }   
            return url
        },
        isIpx() {
            return weex && (weex.config.env.deviceModel === 'iPhone10,3' || weex.config.env.deviceModel === 'iPhone10,6');
        },
        getStream(){
            if(!_stream){
                _stream =  weex.requireModule('stream')
            }
            return _stream;
        },
        GET (api, callback) {
            
            return this.getStream().fetch({
                method: 'GET',
                type: 'json',
                url: this.apiUrl(api)
            }, callback)
        }

    }
}
